﻿<template>
  <div class="twoCategories-container">
    <div class="common-layout">
      <el-container>
        <el-aside width="300px">
          <el-card shadow="hover" :body-style="{ paddingBottom: '0' }">
            <el-form :model="queryParams" ref="queryForm" labelWidth="90">
              <el-row>
                <el-col :xs="24" :sm="12" :md="12" :lg="8" :xl="4" class="mb10" v-if="showAdvanceQueryUI">
                  <h2>工单大类</h2>
                  <el-form-item>
                    <el-button-group style="display: flex; align-items: center;">

                      <el-button plain @click="dialogVisible = true" type="primary" tyle="margin-left:5px;">
                        新增工单类
                      </el-button>
                      <el-dialog v-model="dialogVisible" title="新增工单" width="500" :before-close="handleClose">
                        <el-form-item label="工单分类" prop="OneCategoriesName">
                          <el-input v-model="ruleForm.OneCategoriesName" placeholder="请输入工单分类" maxlength="32"
                            show-word-limit clearable />

                        </el-form-item>
                        <template #footer>
                          <div class="dialog-footer">
                            <el-button @click="dialogVisible = false">取消</el-button>
                            <el-button type="primary" @click="handleClose()">
                              确定
                            </el-button>
                          </div>
                        </template>
                      </el-dialog>



                    </el-button-group>
                  </el-form-item>
                  <ul>
                    <li v-for="(item, index) in oneCategoriesOIdDropdownList" :key="index" :value="item.value"
                      @click="Cahxun(item.value)" :label="item.label">
                      {{ item.label }} <!-- 显示 item 的 label 属性 -->
                    </li>
                  </ul>
                </el-col>

              </el-row>
            </el-form>
          </el-card>
        </el-aside>
        <el-main>
          <el-col :xs="24" :sm="12" :md="12" :lg="8" :xl="4" class="mb10">
            <el-form-item>
              <el-button-group style="display: flex; align-items: center;">

                <el-button type="primary" style="margin-left:5px;" icon="ele-Plus" @click="openAddTwoCategories"
                  v-auth="'twoCategories:add'"> 新增分类 </el-button>

              </el-button-group>
            </el-form-item>

          </el-col>
          <el-card class="full-table" shadow="hover" style="margin-top: 5px">
            <el-table :data="tableData" style="width: 100%" v-loading="loading" tooltip-effect="light" row-key="id"
              @sort-change="sortChange" border="">
              <el-table-c3olumn type="index" label="序号" width="55" align="center" />

              <el-table-column prop="twoCategoriesName" label="二级工单分类" show-overflow-tooltip="" />
              <el-table-column prop="region" label="关联区域" show-overflow-tooltip="" />
              <el-table-column prop="content" label="内容" show-overflow-tooltip="" />
              <el-table-column prop="repairs" label="负责人" show-overflow-tooltip="" />
              <el-table-column label="操作" width="140" align="center" fixed="right" show-overflow-tooltip=""
                v-if="auth('twoCategories:update') || auth('twoCategories:delete')">
                <template #default="scope">
                  <el-button icon="ele-Edit" size="small" text="" type="primary"
                    @click="openEditTwoCategories(scope.row)" v-auth="'twoCategories:update'"> 编辑 </el-button>
                  <el-button icon="ele-Delete" size="small" text="" type="primary" @click="delTwoCategories(scope.row)"
                    v-auth="'twoCategories:delete'"> 删除 </el-button>
                </template>
              </el-table-column>
            </el-table>
            <el-pagination v-model:currentPage="tableParams.page" v-model:page-size="tableParams.pageSize"
              :total="tableParams.total" :page-sizes="[10, 20, 50, 100, 200, 500]" size="small" background=""
              @size-change="handleSizeChange" @current-change="handleCurrentChange"
              layout="total, sizes, prev, pager, next, jumper" />
            <printDialog ref="printDialogRef" :title="printTwoCategoriesTitle" @reloadTable="handleQuery" />
            <editDialog ref="editDialogRef" :title="editTwoCategoriesTitle" @reloadTable="handleQuery" />
          </el-card>
        </el-main>
      </el-container>
    </div>


  </div>
</template>

<script lang="ts" setup="" name="twoCategories">
import { ref } from "vue";
import { ElMessageBox, ElMessage } from "element-plus";
import { auth } from '/@/utils/authFunction';
import { getAPI } from '/@/utils/axios-utils';

import { formatDate } from '/@/utils/formatTime';

import type { FormRules } from "element-plus";
import printDialog from '/@/views/system/print/component/hiprint/preview.vue'
import editDialog from '/@/views/waiter/twoCategories/component/editDialog.vue'
import { pageTwoCategories, deleteTwoCategories } from '/@/api/waiter/twoCategories';
import { getOneCategoriesOIdDropdown, addOne } from '/@/api/waiter/twoCategories';
import { APIJSONApi } from "/@/api-services";
const ruleForm = ref<any>({});
const ruleFormRef = ref();
const dialogVisible = ref(false)
const showAdvanceQueryUI = ref(true);
const printDialogRef = ref();
const editDialogRef = ref();
const loading = ref(false);
const tableData = ref<any>([]);
const queryParams = ref<any>({});
const tableParams = ref({
  page: 1,
  pageSize: 10,
  field: 'createTime', // 默认的排序字段
  order: 'descending', // 排序方向
  descstr: 'descending', // 降序排序的关键字符
  total: 0 as any,
});
const handleClose = async () => {

  var res = await addOne(ruleForm.value);
  console.log(res.data.result);
  ElMessage.success("添加成功");
  dialogVisible.value = false;
  getOneCategoriesOIdDropdownList();
};
const printTwoCategoriesTitle = ref("");
const editTwoCategoriesTitle = ref("");

// 改变高级查询的控件显示状态
const changeAdvanceQueryUI = () => {
  showAdvanceQueryUI.value = !showAdvanceQueryUI.value;
}
const Cahxun = (oId: any) => {
  queryParams.value.oId = oId;
  handleQuery();
}
// 查询操作
const handleQuery = async () => {
  loading.value = true;

  console.log(queryParams.value.oId)
  var res = await pageTwoCategories(Object.assign(queryParams.value, tableParams.value));
  tableData.value = res.data.result?.items ?? [];
  tableParams.value.total = res.data.result?.total;
  loading.value = false;
};

// 列排序
const sortChange = async (column: any) => {
  tableParams.value.field = column.prop;
  tableParams.value.order = column.order;
  await handleQuery();
};

// 打开新增页面
const openAddTwoCategories = () => {
  editTwoCategoriesTitle.value = '添加二级工单';
  editDialogRef.value.openDialog({});
};



// 打开打印页面
const openPrintTwoCategories = async (row: any) => {
  printTwoCategoriesTitle.value = '打印二级工单';
}

// 打开编辑页面
const openEditTwoCategories = (row: any) => {
  editTwoCategoriesTitle.value = '编辑二级工单';
  editDialogRef.value.openDialog(row);
};

// 删除
const delTwoCategories = (row: any) => {
  ElMessageBox.confirm(`确定要删除吗?`, "提示", {
    confirmButtonText: "确定",
    cancelButtonText: "取消",
    type: "warning",
  })
    .then(async () => {
      await deleteTwoCategories(row);
      handleQuery();
      ElMessage.success("删除成功");
    })
    .catch(() => { });
};

// 改变页面容量
const handleSizeChange = (val: number) => {
  tableParams.value.pageSize = val;
  handleQuery();
};

// 改变页码序号
const handleCurrentChange = (val: number) => {
  tableParams.value.page = val;
  handleQuery();
};

const oneCategoriesOIdDropdownList = ref<any>([]);
const getOneCategoriesOIdDropdownList = async () => {
  let list = await getOneCategoriesOIdDropdown();
  oneCategoriesOIdDropdownList.value = list.data.result ?? [];
};
getOneCategoriesOIdDropdownList();

handleQuery();
</script>
<style scoped>
:deep(.el-input),
:deep(.el-select),
:deep(.el-input-number) {
  width: 100%;
}

li {
  margin: 0;
  padding: 15px;
  /* 可以根据需要调整 */
  list-style-type: none;
  /* 移除默认的列表样式 */
}
</style>
